﻿<php>$meta_title = $vo['sale_no']." 订单详情";
     $cache_warehouse = S('warehouse');
</php>
<include file="Public:header" />
<div id="main" class="main" >
    <div class="content">
  <h3 class="heading">编辑销售单 [ <a href="__URL__">返回列表</a> ] 
    <a class="btn btn-success" href="__URL__/invoice/oid/{$vo.id}"> <i class="icon-shopping-cart  icon-white"></i>配货单</a>
        <a class="btn btn-success" href="__URL__/shipping/oid/{$vo.id}"> <i class="icon-plane  icon-white"></i>快递单</a>
        <a class="btn btn-success" href="__APP__/Prepare/out_stock_log/id/{$vo.id}" target="_blank"> <i class="icon-edit  icon-white"></i>缺货登记</a>
        <a class="btn btn-success" href="__URL__/edit_shipping/id/{$vo.id}" target="_blank"> <i class="icon-edit  icon-white"></i>修改收货信息</a>
         <a class="btn btn-success" href="__URL__/send_message/id/{$vo.id}" target="_blank"> <i class="icon-envelope  icon-white"></i>发短信</a>
         <a class="btn btn-warning" href="__APP__/Refund/add/id/{$vo.id}" target="_blank"> <i class="icon-retweet  icon-white"></i>售后退款</a>
         <a class="btn btn-warning" href="__URL__/manual_split_order/id/{$vo.id}"> <i class="icon-th-large  icon-white"></i>人工拆单</a>
         
        <a class="btn btn-info" href="javascript:void(0)" onclick="display_hidden('more1')">隐藏/显示更多</a>
  </h3>
<div id="result" class="result none"></div>
<table cellpadding=3 cellspacing=3 >
    <form class="form-horizontal well" method='post' id="form1" action="__URL__/update/">
    <tr><td colspan="4" class="heading h4 alert alert-info">订单号：{$vo.sale_no} 
        <span class="offset1">原单号：
        <eq name="vo.status" value="0">
        {:modList('Order_source',$vo['order_source_id'],'span2','order_source_id')}
        <input class="span2" type="text" name="mall_no" value="{$vo.mall_no}" />
          <else/>
           {$vo.order_source_id|getModelName='Order_source'} | {$vo.mall_no}
        </eq> 
        </span>
        <span class="offset1">{:configList(C('orderstatus'),$vo['order_status'],'order_status')}</span>
        <span class="offset1">配货:{$vo.prepare_status|getConfigVal="prepare_status"}</span>
        <span class="offset1"> <eq name="vo.status" value="0"> 未审核<else/> 审核通过 </eq> 
         <i class="icon-home"></i> {:$cache_warehouse[$vo['warehouse_id']]} </span>
       </td>
</tr>
    <tr >
        <td>购货人：</td><td>{$vo.customer_name}
            <input type="hidden" name="customer_id" value="{$vo.customer_id}" >
        </td>
        <td>下单时间：</td><td>{$vo.create_time|toDate}</td>
    </tr>
    <tr>
        <td colspan="4">
       <table id="more1" style="display:none;">
    <tr >
        <td>支付方式及时间：</td><td>{$vo.pay_method} {$vo.pay_time|toDate} <!-- &nbsp;&nbsp; 支付宝：{$vo.alipay} --> </td>
        <td>审核时间：</td><td>{$vo.check_time|toDate}</td>
    </tr> 
           
    <tr>
        <td>应收款：</td><td>{$vo.should_pay} , 货款：{$vo.total}，客户实付款： <empty name="vo.real_pay">{$vo.sum_pay} <else/>{$vo.real_pay} </empty> </td>
        <td>快递费：</td><td>{$vo.logifee}</td>
    </tr>
    <tr id="more" >
        <td>快递公司：</td><td>{:modList('Logicompany',$vo['logicompany_id'],'span2','logicompany_id','sort desc' )}发货时间: {$vo.shipping_time|toDate}</td>
        <td>单号：</td><td>{$vo.logino} <!--<input type="text" name="logino" value="{$vo.logino}"> -->  </td>
    </tr>
    
     <tr id="more" > <td>收货人：</td><td>
        <input type="hidden" name="shipping_address_id" value="{$vo.shipping_address_id}" >
        <input type="text" name="shipping_name" value="{$vo.shipping_name}"> 
    </td>
         <td>手机</td><td> <input type="text" name="mobile" value="{$vo.mobile}"> </td>
        
    </tr>
       </table> 
        </td>
    </tr>
    <tr> <td>发票抬头：</td><td><input type="text" name="invoice_title" value="{$vo.invoice_title}"> </td>
        <td>发票内容：</td><td><input type="text" name="invoice_content" value="{$vo.invoice_content}"> </td>
    </tr> 
    <tr id="more" >
       <td colspan="4">地址：
       省份<input class="span1" type="text" name="province" value="{$vo.province}" />
       城市<input class="span1" type="text" name="city" value="{$vo.city}" />
       区县<input class="span1" type="text" name="county" value="{$vo.county}" />
       <input type="text" class="input-xxlarge" name="address" value="{$vo.address}"> 
        电话: <input type="text" name="phone" value="{$vo.phone}"> </td>
    </tr>
    <tr>
        <td colspan="4">客户留言：<input type="text" class="span10" name="customer_msg" value="{$vo.customer_msg}"> </td>
     </tr>

<tr>
    <td colspan="4">备注: <textarea name="remark" rows="1" class="span12">{$vo.remark}</textarea> </td>
</tr>
<?php 
$mall_nos = strpos($vo['mall_no'],',') === false ? $vo['mall_no'] : explode(',', $vo['mall_no']); //分解德生堂合并订单
if(!is_array($mall_nos))
    $messages = M('Message')->where('mall_no = '.$mall_nos.' and depart !=2' )->findAll(); 
else
    foreach ($mall_nos  as $mno) {
        $messages = M('Message')->where('mall_no = '.$mno.' and depart !=2' )->order('create_time asc')->findAll();
        if(is_array($messages))
            break;
        else
            continue;
    }
?>

<volist name="messages" id="msg">
    <tr><td >客服备注:</td><td colspan="3"><span class="label label-important">{$msg.content}  </span> &nbsp;&nbsp;&nbsp;&nbsp; ({$msg.creater_id|getModelName='User'} {$msg.create_time|toDate}) &nbsp;&nbsp;&nbsp;&nbsp;处理状态: {:configList(C('process_status'),2,'process_status[]' )}
    <input type="hidden" name="receiver_id[]" value="{$_SESSION[C('USER_AUTH_KEY')]}" />
    <input name="msg_utime[]" type="hidden" value="{:time()}" />
    <input type="hidden" name="msg_id[]" value="{$msg.id}" />
    </td> </tr>
</volist>
<tr>
	<td>
        <eq name="vo.status" value="0"> 
           <select name="status">
                <option value="1">审核通过</option>
                <option value="0">待审核</option>
            </select>
            </eq>
    </td>
	<td class="center" width="300">
        <input type="hidden" value="{$vo.id}" name="id">
	   <button type="submit" class="btn btn-primary"><i class="icon-ok icon-white"></i> 保存</button>
	<button type="reset" onclick="javascript:history.back()" class="btn btn-info offset1"><i class="icon-arrow-left icon-white"></i> 返回</button>
	</td>
</tr>
</form>
<tr><td colspan="3" class="heading h4 alert alert-info">商品明细--{$vo.sale_no} ( 总数量：{$vo.sum_number})</td> <php>$is_tb = $vo['order_source_id'] == 3 ? 1 :0; </php>
        <td>
            <!--同步德生堂订单-->
        <?php if ($vo['order_source_id'] == 5 or $vo['order_source_id'] == 6 or $vo['order_source_id'] == 8 ): ?>
        <php>if($vo['is_shipping_mall'] == 0 && $vo['order_status'] == 3 ){ </php>
            <a href="__APP__/OrderAPI/dst_shipping_manual/orderno/{$vo.sale_no}/logino/{$vo.logino}/logicompany_id/{$vo.logicompany_id}" class="btn btn-primary">补发货</a> 
        <php>}</php>
            <a href="__APP__/OrderAPI/syncDstSigleOrder/sale_no/{$vo.sale_no}" class="btn btn-primary">重新同步订单</a> 
        <?php endif ?>
        <a href="__APP__/Sale_detail/update_goods/sale_no/{$vo.sale_no}/is_tb/{$is_tb}" class="btn btn-primary">更新商品</a> 
        <a href="__APP__/Sale_detail/add_gift/id/{$vo.id}" class="btn btn-primary">添加赠品</a>
        <a href="__APP__/Sale_detail/add/id/{$vo.id}" class="btn btn-primary">增录新品</a>
        </td>
        
    </tr>
    <tr>
        <td colspan="4">
            <table class="table table-bordered table-striped" id="sale_detail">
                <tr>
                    <th>序号</th><th>ID</th><th>销售标题</th><th class="span2">规格</th><th>编号</th><th>商品名称</th> <th>仓库</th><th>价格</th><th>数量</th><th class="span1">单位</th><th>小计</th><th>库存</th><th>修改</th><th>删除</th>
                </tr>
                <php>$sale_details = M('Sale_detail')->where('sale_no ="'.$vo['sale_no'].'"')->order('id')->findAll();
                     $cache_goods = S('goods');
                </php>
                <volist name="sale_details" id="sa">
                    <form action="__APP__/Sale_detail/update" method="post">
                    <tr>
                        <td>{$key+1} <input type="hidden" name="id" value="{$sa.id}"> 
                            <input type="hidden" name="update_time" value="{:time()}">
                         </td>
                         <td>{$sa.id}</td>
                        <td>
                        <textarea id="" class="span7" name="sale_title" cols="30" rows="2">{$sa.sale_title}</textarea>
                            <notempty name="sa.options"> <input type="text" name="options" value="{$sa.options}">
                                <else/>
                                <input type="hidden" name="options" value="">
                            </notempty>
                            </td>
                        <td>
                           {$sa.product_id|printGoodsOption} 
                           <a href="__APP__/Product_map?keywords={$sa.out_number}" target="_blank">{$sa.out_number}</a>
                           <input type="hidden" name="out_number" value="{$sa.out_number}">
                           <input type="hidden" name="order_source_id" value="{$vo.order_source_id}">
                           <eq name="sa.is_gift" value="1"><img src="__PUBLIC__/Images/gift.jpg" width="40" height="40"> </eq>
                           <?php $is_virtual = getModelName($sa['product_id'],'Product','is_virtual'); ?>
                           <eq name="is_virtual" value="1">[虚拟商品]</eq>  
                        </td>
                        <td>{$sa.product_id}</td>
                        <td class="span6">{:$cache_goods[$sa['product_id']]['name']}</td>
                        <td>{:$cache_warehouse[$sa['warehouse_id']]}</td>
                        <td>
                            <input type="text" name="price" class="span1" value="{$sa.price}">
                        </td>
                        <td><input type="text" name="number" value="{$sa.number}" class="span1" > </td>
                        <td>{$sa.product_id|getProductUnit}</td>
                        <td>{$sa.total}</td>
                        <td>{$sa.product_id|getDStock}</td>
                        <td> 
                            <input type="hidden" name="jumpUrl" value="__URL__/edit/id/{$vo.id}">
                            <input type="submit" value="修改" class ="btn"> 
                        </td>
                        <td><a href="__APP__/Sale_detail/foreverdelete/id/{$sa.id}" class="btn">删除</a>  </td>
                        <td> <a href="javascript:void(0)" class='btn' onclick="copy_sale_detail({$sa.id})">复制</a> </td>
                    </tr>
                    </form>
                </volist>
            </table>
        </td>
    </tr>
    <tr><td colspan="4" class="heading h4 alert alert-info">最近订单信息（等待发货） </td></tr>
    <tr>
        <td colspan="4">
            <table class="table table-bordered table-striped">
                <tr>
                    <th>序号</th><th>销售标题</th><th class="span2">规格</th><th>商品编号</th><th>商品名称</th><th>仓库</th> <th>价格</th><th>数量</th><th class="span1">单位</th><th>小计</th><th>订单号</th>
                </tr>
                <php>
                    $map = array(
                        //'Sale.customer_id' => $vo['customer_id'],
                        //'Sale.address' => $vo['address'],
                        'shipping_address_id' => $vo['shipping_address_id'],
                        'order_status' => 2, //等待卖家发货
                        'id' => array('neq',$vo['id']),

                    );
                    $sale_history = D('Sale')->where($map)->field('id')->findAll(); //same sale ids 
                </php>
                <volist name="sale_history" id="shid">
                   <php>$shs = M('Sale_detail')->where('sale_id = '.$shid['id'])->field('sale_title,options,product_id,warehouse_id,price,number,total,sale_no')->findAll(); </php>
                   <tr><td><a href="__URL__/edit/id/{$shid.id}" target="_blank" >{$shs.0.sale_no}</a>  </td> </tr>
                   <volist name="shs" id = "sh">
                    <tr>
                        <td>{$key+1} </td>
                        <td>{$sh.sale_title} {$sh.options}</td>
                        <td>
                           {$sh.product_id|printGoodsOption}
                        </td>
                        <td>{$sh.product_id}</td>
                        <td>{:$cache_goods[$sh['product_id']]['name']}</td>
                        <td>{:$cache_warehouse[$sh['warehouse_id']]}</td>
                        <td>{$sh.price}</td>
                        <td> {$sh.number}</td>
                        <td>{$sh.product_id|getProductUnit}</td>
                        <td>{$sh.total}</td>
                        <td>{$sh.sale_no}</td>
                    </tr>
                    </volist>
                </volist>
            </table>
        </td>
    </tr>
    <tr><td colspan="4" class="heading h4 alert alert-info"><a class="btn btn-danger" href="__URL__/more/id/{$vo.id}" target="_blank">操作日志</a> </td></tr>
</table>

</div>
</div>
<include file="Public:footer" />
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/easyui/themes/default/easyui.css">
<script type="text/javascript" src="__PUBLIC__/Js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/filter-product.js"></script>
<script type="text/javascript">
    function copy_sale_detail (id) {
        var sale_detail_id = id;
        if( sale_detail_id > 0){
        jQuery.post(
        APP+'/Sale_detail/getSaleDetail',
        {   sale_detail_id:sale_detail_id
        },
        function(data){
            data = data.data;
            $('#sale_detail').append(data.sale_detail);
        },
        'json'
        );
        }
    }

    function display_hidden(element)
    {
        var d=document.getElementById(element);
        if(d.style.display=='block')
            {
                d.style.display='none';
            }
        else
            {
            d.style.display="block";
        }
    }
</script>
